package services

import (
	"ContentSystem/internal/api/operate"
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

type ContentUpdateReq struct {
	ID             int           `json:"id" binding:"required" `
	Title          string        `json:"title"  `
	Description    string        `json:"description" `
	Author         string        `json:"author"`
	VideoURL       string        `json:"video_url"`
	Thumbnail      string        `json:"thumbnail"`
	Category       string        `json:"category"`
	Duration       time.Duration `json:"duration"`
	Resolution     string        `json:"resolution"`
	FileSize       string        `json:"file_size"`
	Format         string        `json:"format"`
	Quality        int           `json:"quality"`
	ApprovalStatus int           `json:"approval_status"`
	CreatedAt      time.Time     `json:"created_at"`
	UpdatedAt      time.Time     `json:"updated_at"`
}

type ContentUpdateResp struct {
	Message string `json:"message" binding:"required"`
}

func (c *CmsApp) ContentUpdate(ctx *gin.Context) {

	var req ContentUpdateReq
	if err := ctx.ShouldBindJSON(&req); err != nil {
		ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}

	resp, err := c.operateAppClient.UpdateContent(ctx, &operate.UpdateContentReq{
		Content: &operate.Content{
			Id:          int64(req.ID),
			Title:       req.Title,
			Description: req.Description,
			Author:      req.Author,
			VideoUrl:    req.VideoURL,
			Thumbnail:   req.Thumbnail,
			Category:    req.Category,

			Resolution: req.Resolution,

			Format: req.Format,
		},
	})
	//
	//contentDao := dao.NewContentDao(c.db)
	//ok, err := contentDao.IsExist(req.ID)
	if err != nil {
		ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
		return
	}
	//
	//if !ok {
	//	ctx.JSON(http.StatusInternalServerError, gin.H{"error": "内容不存在"})
	//	return
	//}
	//
	//if err := contentDao.Update(req.ID, model.ContentDetail{
	//	Title:          req.Title,
	//	Description:    req.Description,
	//	Author:         req.Author,
	//	VideoURL:       req.VideoURL,
	//	Thumbnail:      req.Thumbnail,
	//	Category:       req.Category,
	//	Duration:       req.Duration,
	//	Resolution:     req.Resolution,
	//	FileSize:       req.FileSize,
	//	Format:         req.Format,
	//	Quality:        req.Quality,
	//	ApprovalStatus: req.ApprovalStatus,
	//}); err != nil {
	//	ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
	//	return
	//}
	// 响应
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"message": "ok",
		"data":    resp,
	})

}
